var express = require('express');//环境
var router = express.Router();//引入路由
let movieService=require("../service/hotsUpSrevise.js");
//获取数据的路由
router.get("/hotsup",async(req,res)=>{

    //查询
    let { key, val, page, limit } = req.query;
    console.log(key,val);
    let filter=null;
    if (key==="name") {
        filter={"name":{$regex: new RegExp(val)}}
        
    }
    if(key==="time"){
        filter={"time": Number(val) }
    }
    // console.log(filter);//

    let data=await movieService.hotList(filter, page, limit);
    res.send(data);
});

//添加数据接口
router.post("/addhots",async (req,res)=> {
    let movies=req.body;
    let data=await movieService.addMovies(movies);
    res.send(data);
})

//删除数据接口
router.post("/deletMovie",async (req,res)=>{
    let movieId=req.body;
    console.log(movieId);
    let data=await movieService.deletMovie(movieId);
    res.send(data);

})

//通过id查找接口

router.post("/getById",async (req,res)=>{
    let bookId=req.body;
    let data=await movieService.getById(bookId);
    res.send(data);
})

//修改电影接口

router.post("/updateById",async(req,res)=>{
    let movie=req.body;
    console.log(book);
    let data=await movieService.updateById(movie)
    res.send(data);
})
module.exports=router;